package com.xiegang.apidriver.service;

import com.xiegang.apidriver.remote.ServiceDriverUserClient;
import com.xiegang.apidriver.remote.ServiceMapClient;
import com.xiegang.internalcommon.dto.Car;
import com.xiegang.internalcommon.dto.ResponseResult;
import com.xiegang.internalcommon.request.ApiDriverPointRequest;
import com.xiegang.internalcommon.request.PointRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author xieGang
 * @description
 * @date 2023/4/5 13:53
 **/
@Service
public class PointService {

    @Autowired
    private ServiceDriverUserClient serviceDriverUserClient;

    @Autowired
    private ServiceMapClient serviceMapClient;

    public ResponseResult upload(ApiDriverPointRequest apiDriverPointRequest) {
        Long carId = apiDriverPointRequest.getCarId();
        ResponseResult<Car> responseResult = serviceDriverUserClient.getCarByCarId(carId);
        String tid = responseResult.getData().getTid();
        String trid = responseResult.getData().getTrid();

        PointRequest pointRequest = new PointRequest();
        pointRequest.setTid(tid);
        pointRequest.setTrid(trid);
        pointRequest.setPoints(apiDriverPointRequest.getPoints());

        return serviceMapClient.upload(pointRequest);
    }
}
